package com.example.zyflutter.plugin

import com.example.zyflutter.utils.LogUtils
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

/// 测试通信使用:MethodChannel
class SampleBridgeMethodChannelPlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
    lateinit var methodChannel: MethodChannel

    override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
        LogUtils.logE("SampleBridgeMethodChannelPlugin", "onAttachedToEngine");
        methodChannel = MethodChannel(binding.binaryMessenger, "com.example.zyflutter.action.zymc")
        methodChannel.setMethodCallHandler(this)
    }

    override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
        LogUtils.logE("SampleBridgeMethodChannelPlugin", "onDetachedFromEngine");
    }

    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
        LogUtils.logE("SampleBridgeMethodChannelPlugin", "onMethodCall");
        if (call.method == "request") {
            result.success("reply: 30111")
        } else {
            result.notImplemented()
        }
    }
}